import java.util.Scanner;

/**
 * @Title: 分解质因数
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/15 11:15
 * @description:
 */
public class 分解质因数 {
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long n = sc.nextLong();
        for(long i = 1; i <= n; ++ i ) {
            long x = sc.nextLong();
            solution(x);
        }
    }

    public static void solution(long x) {
        //拆分x
        for(int i = 2; i <= x / i; ++ i ) {
            if(x % i == 0) {
                int cnt = 0;
                while(x % i == 0) {
                    x /= i;
                    cnt++;
                }
                System.out.println(i + " " + cnt);
            }
        }
        if(x > 1) {
            System.out.println(x + " " + 1);
        }
        System.out.println();
    }
}
